package net.adetech.crj.web;

import com.alibaba.fastjson.JSON;
import net.adetech.crj.bean.PaperProgress;
import net.adetech.crj.entity.User;
import net.adetech.crj.utils.ServiceUtil;
import net.adetech.framework.entity.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ProgressWebController {
    @Autowired
    ServiceUtil serviceUtil;

    @RequestMapping(value = "/progress/page/list")
    public String progressList(HttpSession session, Model model)
    {
        User user = (User)session.getAttribute("currentUser");
        String sfzh = user.getIdNumber();
        if (sfzh==null)
        {
            return "queryProgress";
        }


        ServiceResponse serviceResponse = serviceUtil.callService("paper.getProgressListBySfzh","sfzh",sfzh);
        List<PaperProgress> progressList = (List<PaperProgress>)serviceResponse.getResults().get("progressList");
        if (progressList==null||progressList.size()<=0)
        {
            return "queryProgress";
        }
        String progressListJson = JSON.toJSONString(progressList);
        model.addAttribute("progressListJson","var progressList = "+progressListJson+";");
        return "paperProgressList";
    }

    @RequestMapping(value = "/progress/page/query")
    public String progressQuery()
    {
        return "queryProgress";
    }
}
